import 'package:juming_test/model/home/home_kingkong_model.dart';
import 'package:juming_test/model/home/kingkong_management_section_model.dart';
import 'package:logger/logger.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
import 'package:juming_test/model/home/home_banner_model.dart';
import 'package:juming_test/model/home/home_domain_model.dart';
import 'package:juming_test/model/home/home_notice_model.dart';

class HomeAction {
  // 日志打印
  final Logger logger = Logger();

  // 获取域名数据
  static Future<HomeDomainModel> fetchDomainData() async {
    String jsonString = await rootBundle.loadString(
      'assets/jsons/home_domain.json',
    );
    Map<String, dynamic> jsonMap = json.decode(jsonString);
    return HomeDomainModel.fromJson(jsonMap);
  }

  // 获取公告栏数据
  static Future<List<HomeNoticeModel>> fetchNoticeList() async {
    String jsonString = await rootBundle.loadString(
      'assets/jsons/home_notice.json',
    );
    List<dynamic> jsonList = json.decode(jsonString);
    return jsonList.map((json) => HomeNoticeModel.fromJson(json)).toList();
  }

  // 获取banner数据
  static Future<List<HomeBannerModel>> fetchBannerList() async {
    String jsonString = await rootBundle.loadString(
      'assets/jsons/home_banner.json',
    );
    List<dynamic> jsonList = json.decode(jsonString);
    return jsonList.map((json) => HomeBannerModel.fromJson(json)).toList();
  }

  // 获取首页金刚位数据
  static Future<List<HomeKingkongModel>> fetchHomeKingkongList() async {
    String jsonString = await rootBundle.loadString(
      'assets/jsons/home_kingkong_mine.json',
    );
    List<dynamic> jsonList = json.decode(jsonString);
    return jsonList.map((json) => HomeKingkongModel.fromJson(json)).toList();
  }

  // 获取全部金刚位数据
  static Future<List<KingkongManagementSectionModel>>
  fetchAllKingkongList() async {
    String jsonString = await rootBundle.loadString(
      'assets/jsons/home_kingkong_all.json',
    );
    List<dynamic> jsonList = json.decode(jsonString);
    return jsonList.map((json) {
      return KingkongManagementSectionModel.fromJson(json);
    }).toList();
  }
}
